<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->

<h2>Status</h2>
<table class="table table-bordered table-striped" class="col-md-6">
    <tbody>
    <tr>
        <td>Rpc port</td>
        <td>{{$ctrl.overview.jmx.RpcPort}}</td>
    </tr>
    <tr>
        <td>OM Id</td>
        <td>{{$ctrl.role.Id}}</td>
    </tr>
    <tr>
        <td>Current-Role</td>
        <td>{{$ctrl.role.Role}}</td>
    </tr>
    <tr>
        <td>Group-Id</td>
        <td>{{$ctrl.role.GroupId}}</td>
    </tr>
    <tr ng-hide="!$ctrl.electionCount.Count || $ctrl.electionCount.Count==-1">
        <td>Election-Count</td>
        <td>{{$ctrl.electionCount.Count}}</td>
    </tr>
    <tr ng-hide="!$ctrl.elapsedTime.Value || $ctrl.elapsedTime.Value==-1">
        <td>Last Election Elapsed Time</td>
        <td>{{$ctrl.elapsedTime.Value}}</td>
    </tr>
    </tbody>
</table>

<h2>OM Roles (HA)</h2>
<h4 ng-show="$ctrl.overview.jmx.RatisRoles.length == 1 && $ctrl.overview.jmx.RatisRoles[0].length == 1">{{$ctrl.overview.jmx.RatisRoles[0][0]}}</h4>
<div ng-show="$ctrl.overview.jmx.RatisRoles.length > 1">
    <table class="table table-striped table-bordered" class="col-md-6">
        <thead>
        <tr>
            <th>Host Name</th>
            <th>Node ID</th>
            <th>Ratis Port</th>
            <th>Role</th>
            <th>Leader Readiness</th>
        </tr>
        </thead>
        <tbody ng-repeat="roles in $ctrl.overview.jmx.RatisRoles">
        <tr class="om-roles-background" ng-if="$ctrl.role.Id == roles[1]">
            <td>{{roles[0]}}</td>
            <td>{{roles[1]}}</td>
            <td>{{roles[2]}}</td>
            <td>{{roles[3]}}</td>
            <td>{{roles[4]}}</td>
        </tr>
        <tr ng-if="$ctrl.role.Id != roles[1]">
            <td>{{roles[0]}}</td>
            <td>{{roles[1]}}</td>
            <td>{{roles[2]}}</td>
            <td>{{roles[3]}}</td>
            <td>{{roles[4]}}</td>
        </tr>
        </tbody>
    </table>
</div>


<h2>Meta-Data Volume Information</h2>
<table class="table table-bordered table-striped" class="col-md-6">
    <tbody>
    <tr>
        <td>Ratis Log directory</td>
        <td>{{$ctrl.overview.jmx.RatisLogDirectory}}</td>
    </tr>
    <tr>
        <td>RocksDB Directory</td>
        <td>{{$ctrl.overview.jmx.RocksDbDirectory}}</td>
    </tr>
    </tbody>
</table>

<!-- Only display Deletion Progress on OM leader -->
<div ng-show="$ctrl.role.Role.trim() === 'LEADER'">
  <h2>Deletion Progress [since {{$ctrl.overview.jmx.MetricsResetTimeStamp * 1000 | date:'yyyy-MM-dd HH:mm:ss'}}]
    &nbsp;&nbsp;•&nbsp;&nbsp;
    <b>Size Reclaimed:</b> {{$ctrl.formatBytes($ctrl.overview.jmx.ReclaimedSizeInInterval)}}
    &nbsp;&nbsp;•&nbsp;&nbsp;
    <b>Keys Reclaimed:</b> {{$ctrl.overview.jmx.KeysReclaimedInInterval}}
  </h2>
  <div class="mt-4">
      <div class="mt-3">
          <div class="col-md-12">
              <button class="btn btn-sm btn-link p-0" ng-click="lastRunDetailsVisible = !lastRunDetailsVisible">
                  {{ lastRunDetailsVisible ? 'Last Run Details(-)' : 'Last Run Details(+)' }}
              </button>
          </div>
          <div ng-show="lastRunDetailsVisible">
              <div class="mt-3">
                  <div class="row mb-2" ng-if="$ctrl.overview.jmx.KdsCurRunTimestamp">
                      <div class="col-md-3"><b>Current Run Started:</b></div>
                      <div class="col-md-9">{{$ctrl.convertMsToTime($ctrl.Date.now() - $ctrl.overview.jmx.KdsCurRunTimestamp)}} ago</div>
                  </div>
                  <div class="row mb-2" ng-if="$ctrl.overview.jmx.KdsLastRunTimestamp">
                      <div class="col-md-3"><b>Last Run:</b></div>
                      <div class="col-md-9">{{$ctrl.convertMsToTime($ctrl.Date.now() - $ctrl.overview.jmx.KdsLastRunTimestamp)}} ago</div>
                  </div>
              </div>
              <div style="margin-bottom: 2px;"></div>
              <table class="table table-sm table-bordered mt-2">
                  <thead>
                      <tr>
                          <th>Store</th>
                          <th>Reclaimed Size</th>
                          <th>#Reclaimed Keys</th>
                          <th>#Iterated Keys</th>
                          <th>#NotReclaimable Keys (Referred by Snapshots)</th>
                      </tr>
                  </thead>
                  <tbody>
                      <tr>
                          <td>Active Object Store</td>
                          <td>{{$ctrl.formatBytes($ctrl.overview.jmx.AosReclaimedSizeLast)}}</td>
                          <td>{{$ctrl.overview.jmx.AosKeysReclaimedLast || 0}}</td>
                          <td>{{$ctrl.overview.jmx.AosKeysIteratedLast || 0}}</td>
                          <td>{{$ctrl.overview.jmx.AosKeysNotReclaimableLast || 0}}</td>
                      </tr>
                      <tr>
                          <td>Snapshots</td>
                          <td>{{$ctrl.formatBytes($ctrl.overview.jmx.SnapReclaimedSizeLast)}}</td>
                          <td>{{$ctrl.overview.jmx.SnapKeysReclaimedLast || 0}}</td>
                          <td>{{$ctrl.overview.jmx.SnapKeysIteratedLast || 0}}</td>
                          <td>{{$ctrl.overview.jmx.SnapKeysNotReclaimableLast || 0}}</td>
                      </tr>
                  </tbody>
              </table>
          </div>
      </div>
  </div>
</div>
